﻿using CommonTools;
using shop.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shop.Bll.cost
{
    public class ShuadanConfigBll
    {
        public async Task<Result> SaveConfig(IEnumerable<ShuadanConfig> items)
        {
            if (items == null)
                return new Result(false, "系统错误");

            await DB.FSql.InsertOrUpdate<ShuadanConfig>()
                .SetSource(items)
                .ExecuteAffrowsAsync();

            return new Result(true);
        }

        public async Task<IEnumerable<ShuadanConfig>> QueryItems()
        {
            return await DB.FSql.Select<ShuadanConfig>()
                .Where(a=> !string.IsNullOrEmpty(a.ShuadanStock))
                .ToListAsync();
        }

        public async Task<Result> DeleteItem(int id)
        {
            await DB.FSql.Delete<ShuadanConfig>()
                .Where(a => a.id == id)
                .ExecuteAffrowsAsync();

            return new Result(true);
        }


        public async Task<IEnumerable<ShuadanConfig>> QueryBufaItems()
        {
            return await DB.FSql.Select<ShuadanConfig>()
            .Where(a => !string.IsNullOrEmpty(a.Bufa))
            .ToListAsync();
        }


        public async Task<Result> SaveBufaItems(IEnumerable<ShuadanConfig> items)
        {
            if (items == null)
                return new Result(false, "系统错误");

            foreach (var item in items)
            {
                if(string.IsNullOrEmpty(item.Bufa))
                {
                    return new Result(false, "类型不能为空");
                }

            }

            await DB.FSql.InsertOrUpdate<ShuadanConfig>()
                .SetSource(items)
                .ExecuteAffrowsAsync();

            return new Result(true);
        }



    }
}
